package com.aspose.cells;

class zcev {
   static boolean a(byte[] var0, int var1) {
      int var2 = var0.length;
      if (var1 == -1) {
         var2 = com.aspose.cells.b.a.zc.a(var0, 0);
         var1 = 4;
      }

      if (var0[var1] != 23) {
         return false;
      } else {
         int var3 = com.aspose.cells.b.a.zc.e(var0, var1 + 1) & '\uffff';
         return var2 == var3 * 2 + 3;
      }
   }

   private static boolean a(String var0, int[] var1) {
      var1[0] = 0;
      if (var0 != null && var0.length() <= 3) {
         for(int var2 = 0; var2 < var0.length(); ++var2) {
            if (!Character.isLetter(var0.charAt(var2))) {
               return false;
            }

            var1[0] = var1[0] * 26 + var0.charAt(var2) - 65 + 1;
         }

         if (var1[0] > 0) {
            --var1[0];
         }

         if (var1[0] <= 16383 && var1[0] >= 0) {
            return true;
         } else {
            return false;
         }
      } else {
         return false;
      }
   }

   static boolean a(String var0, int[] var1, int[] var2, boolean[] var3, boolean[] var4, boolean[] var5, boolean[] var6) {
      var1[0] = -1;
      var2[0] = -1;
      var3[0] = false;
      var4[0] = false;
      if (var0 == null) {
         return false;
      } else {
         var0 = var0.toUpperCase();
         char[] var7 = var0.toCharArray();
         boolean var8 = false;

         for(int var9 = 0; var9 < var7.length; ++var9) {
            int var10;
            if (Character.isLetter(var7[var9])) {
               if (var2[0] != -1) {
                  return false;
               }

               var10 = var9;
               if (var9 != 0 && var7[var9 - 1] == '$') {
                  var4[0] = true;
               }

               while(var9 < var7.length && Character.isLetter(var7[var9])) {
                  ++var9;
               }

               if (!a(var0.substring(var10, var10 + (var9 - var10)), var2)) {
                  return false;
               }

               if (var9 != var7.length) {
                  --var9;
               }
            } else if (!Character.isDigit(var7[var9])) {
               if (var7[var9] != '$') {
                  return false;
               }

               if (var9 == var7.length - 1) {
                  return false;
               }

               if (var9 != 0 && var7[var9 - 1] == '$') {
                  return false;
               }
            } else {
               if (var1[0] != -1) {
                  return false;
               }

               var10 = var9;
               if (var9 != 0 && var7[var9 - 1] == '$') {
                  var3[0] = true;
               }

               while(var9 < var7.length && Character.isDigit(var7[var9])) {
                  ++var9;
               }

               var1[0] = com.aspose.cells.b.a.zo.a(var0.substring(var10, var10 + (var9 - var10))) - 1;
               if (var1[0] > 1048575) {
                  return false;
               }

               if (var9 != var7.length) {
                  return false;
               }
            }
         }

         var6[0] = var1[0] == -1;
         var5[0] = var2[0] == -1;
         return true;
      }
   }

   public static boolean a(String var0) {
      if (var0 != null && !"".equals(var0)) {
         var0 = var0.toUpperCase();
         char[] var1 = var0.toCharArray();
         boolean var2 = false;
         int var3 = -1;
         int var4 = -1;

         for(int var5 = 0; var5 < var1.length; ++var5) {
            int var8;
            if (Character.isLetter(var1[var5])) {
               if (var3 != -1) {
                  return false;
               }

               for(var8 = var5; var5 < var1.length && Character.isLetter(var1[var5]); ++var5) {
                  ;
               }

               int[] var6 = new int[]{var3};
               boolean var7 = !a(var0.substring(var8, var8 + (var5 - var8)), var6);
               var3 = var6[0];
               if (var7) {
                  return false;
               }

               if (var5 == var1.length) {
                  return false;
               }

               --var5;
            } else if (!Character.isDigit(var1[var5])) {
               if (var1[var5] != '$') {
                  return false;
               }

               if (var5 == var1.length - 1) {
                  return false;
               }

               if (var5 != 0 && var1[var5 - 1] == '$') {
                  return false;
               }
            } else {
               if (var4 != -1) {
                  return false;
               }

               for(var8 = var5; var5 < var1.length && Character.isDigit(var1[var5]); ++var5) {
                  ;
               }

               var4 = com.aspose.cells.b.a.zo.a(var0.substring(var8, var8 + (var5 - var8))) - 1;
               if (var4 > 1048575) {
                  return false;
               }

               if (var5 != var1.length) {
                  return false;
               }
            }
         }

         return true;
      } else {
         return false;
      }
   }

   static byte[] a(WorksheetCollection var0, int var1, String var2, boolean var3, boolean var4, boolean var5, boolean[] var6) {
      boolean var7 = true;
      boolean var8 = true;
      boolean var9 = true;
      boolean var10 = true;
      var6[0] = true;
      if (var2.charAt(0) == '=') {
         var2 = var2.substring(1);
      }

      com.aspose.cells.b.a.g.a.ze var11 = new com.aspose.cells.b.a.g.a.ze("!");
      com.aspose.cells.b.a.g.a.zc var12 = var11.a(var2);
      boolean var13 = false;
      int var47;
      int var48;
      if (var12.c()) {
         var13 = true;
         String var14 = var2.substring(0, 0 + var12.d()).trim();
         if (var14.charAt(0) == '\'' && var14.charAt(var14.length() - 1) == '\'') {
            var14 = var14.substring(1, 1 + (var14.length() - 2));
            if (var14 == null || "".equals(var14)) {
               throw new CellsException(15, "Invalid worksheet name.");
            }
         }

         int[] var15 = zyn.a(var0, var14);
         var47 = var15[0];
         var48 = var15[1];
         int var45 = var15[2];
         int var46 = var15[3];
         if (var47 == -1) {
            throw new CellsException(15, "Invalid worksheet name.");
         }

         var1 = var45;
         var2 = var2.substring(var12.d() + 1).trim();
      } else {
         var48 = var0.u();
         var47 = var0.q().b(var0.u(), var1);
      }

      var11 = new com.aspose.cells.b.a.g.a.ze(":");
      com.aspose.cells.b.a.g.a.zc var49 = var11.a(var2);
      Object var50 = null;
      byte var16;
      byte var17;
      boolean var18;
      boolean var19;
      boolean var20;
      boolean var21;
      boolean var22;
      byte[] var51;
      int var52;
      int var53;
      if (var49.c()) {
         var16 = 0;
         var17 = 0;
         var18 = false;
         var19 = false;
         var20 = false;
         var21 = false;
         var22 = true;
         byte var56 = 0;
         byte var58 = 0;
         boolean var60 = false;
         boolean var61 = false;
         boolean var62 = false;
         boolean var63 = false;
         boolean var29 = true;
         String var30 = var2.substring(0, 0 + var49.d()).trim();
         String var31 = var2.substring(var49.d() + 1).trim();
         int[] var32 = new int[]{var16};
         int[] var33 = new int[]{var17};
         boolean[] var34 = new boolean[]{var20};
         boolean[] var35 = new boolean[]{var21};
         boolean[] var36 = new boolean[]{var18};
         boolean[] var37 = new boolean[]{var19};
         var22 = a(var30, var32, var33, var34, var35, var36, var37);
         var52 = var32[0];
         var53 = var33[0];
         var20 = var34[0];
         var21 = var35[0];
         var18 = var36[0];
         var19 = var37[0];
         if (!var22) {
            throw new CellsException(6, "Invalid cell range.");
         } else {
            int[] var38 = new int[]{var56};
            int[] var39 = new int[]{var58};
            boolean[] var40 = new boolean[]{var62};
            boolean[] var41 = new boolean[]{var63};
            boolean[] var42 = new boolean[]{var60};
            boolean[] var43 = new boolean[]{var61};
            var29 = a(var31, var38, var39, var40, var41, var42, var43);
            int var57 = var38[0];
            int var59 = var39[0];
            var62 = var40[0];
            var63 = var41[0];
            var60 = var42[0];
            var61 = var43[0];
            if (!var29) {
               throw new CellsException(6, "Invalid cell range.");
            } else if (var18 == var60 && var19 == var61) {
               byte var44 = 1;
               if (!var13 && !var3) {
                  var51 = new byte[13];
                  var51[0] = 37;
               } else {
                  var51 = new byte[15];
                  var51[0] = 59;
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var47), 0, var51, 1, 2);
                  var44 = 3;
               }

               if (var18) {
                  zcew.a(var51, var44, var52, 0, var20, false);
                  zcew.a(var51, var44 + 4, var57, 0, var62, false);
                  zcew.c(var51, var44 + 10, 16383, 0, var63, false);
               } else if (var19) {
                  zcew.a(var51, var44 + 4, 1048575, 0, var62, false);
                  zcew.c(var51, var44 + 8, var53, 0, var21, false);
                  zcew.c(var51, var44 + 10, var59, 0, var63, false);
               } else {
                  zcew.a(var51, var44, var52, 0, var20, false);
                  zcew.a(var51, var44 + 4, var57, 0, var62, false);
                  zcew.c(var51, var44 + 8, var53, 0, var21, false);
                  zcew.c(var51, var44 + 10, var59, 0, var63, false);
               }

               return var51;
            } else {
               throw new CellsException(6, "Invalid cell range.");
            }
         }
      } else {
         var16 = 0;
         var17 = 0;
         var18 = false;
         var19 = false;
         var20 = false;
         var21 = false;
         var22 = true;
         int[] var23 = new int[]{var16};
         int[] var24 = new int[]{var17};
         boolean[] var25 = new boolean[]{var20};
         boolean[] var26 = new boolean[]{var21};
         boolean[] var27 = new boolean[]{var18};
         boolean[] var28 = new boolean[]{var19};
         var22 = a(var2, var23, var24, var25, var26, var27, var28);
         var52 = var23[0];
         var53 = var24[0];
         var20 = var25[0];
         var21 = var26[0];
         var18 = var27[0];
         var19 = var28[0];
         if (var22 && !var18 && !var19) {
            if (!var13 && !var3) {
               var51 = new byte[7];
               var51[0] = 36;
               zcew.a(var51, 1, var52, 0, var20, false);
               zcew.c(var51, 5, var53, 0, var21, false);
            } else {
               var51 = new byte[9];
               var51[0] = 58;
               System.arraycopy(com.aspose.cells.b.a.zc.a(var47), 0, var51, 1, 2);
               zcew.a(var51, 3, var52, 0, var20, false);
               zcew.c(var51, 7, var53, 0, var21, false);
            }

            return var51;
         } else if (!var4) {
            var6[0] = false;
            return null;
         } else {
            if (var2.length() > 0 && var2.charAt(0) == '\'') {
               var2 = var2.substring(1, 1 + (var2.length() - 2));
            }

            if (var48 == var0.u()) {
               var52 = var0.getNames().a(var2, var1, !var13);
               if (var52 == -1) {
                  var6[0] = false;
                  return null;
               }

               Name var54 = var0.getNames().get(var52);
               Range var55 = var54.s();
               if (var55 == null) {
                  var6[0] = false;
                  return null;
               }

               if (var13) {
                  var51 = new byte[7];
                  var51[0] = 57;
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var47), 0, var51, 1, 2);
                  System.arraycopy(com.aspose.cells.b.a.zc.a((var52 & '\uffff') + 1), 0, var51, 3, 2);
               } else if (var5) {
                  var51 = var54.q();
               } else {
                  var51 = new byte[5];
                  var51[0] = 35;
                  System.arraycopy(com.aspose.cells.b.a.zc.a((var52 & '\uffff') + 1), 0, var51, 1, 2);
               }
            } else {
               var51 = zcfd.a(var0, var48, var47, var1, var2, 1, 32);
            }

            return var51;
         }
      }
   }
}
